/*
 *  Autores: Claudio Djohnnatha, David Guilherme, Jailson Lima e Jordan Lira.
 *
 *  Projeto da disciplina Linguagem de Programação 2.
 *
 *  Arquivo: BucketColor.java
 *
 *  Data: 27/08/2013
 *
 */



import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;

public class BucketColor extends JLabel
{
   private Color color;

   private JTextPane pane;

   private boolean select = false;

   public BucketColor( Color c, JTextPane p )
   {
      setLayout( null );
      setSize( 24, 24 );

      color = c;
      pane = p;

      // Eventos de mouse.
      addMouseListener(
         new MouseAdapter() // Classe interna anônima.
         {
            public void mouseEntered( MouseEvent event )
            {
               select = true;
               repaint();
            }

            public void mouseExited( MouseEvent event )
            {
               select = false;
               repaint();
            }

            public void mousePressed( MouseEvent event )
            {
               pane.setForeground( color );
            }
         }
      );
   }

   public void paintComponent( Graphics g )
   {
      super.paintComponent( g );

      if ( select )
      {
         g.setColor( color );
         g.fillRect( 1, 1, 22, 22 );
         g.setColor( new Color( 48, 48, 48 ) );
         g.drawRect( 0, 0, 23, 23 );
      }
      else
      {
         g.setColor( color );
         g.fillRect( 1, 1, 22, 22 );
      }
   }

}